﻿using UnityEngine;
using System.Collections;

public class Calculator
{

    public static float AngleInSight(Transform selfTrans, Vector3 targetPoint)
    {

        return Vector2.Angle(new Vector2(selfTrans.forward.x, selfTrans.forward.z), new Vector2(Vector3.Normalize(targetPoint - selfTrans.position).x, Vector3.Normalize(targetPoint - selfTrans.position).z));
    }
    public static bool IsInSight(GameObject self, Vector3 target, float angle)
    {
        float tAngle = AngleInSight(self.transform, target);

        return Mathf.Abs(tAngle) < angle / 2;
    }
    public static Vector3 RotateTo(Vector3 from, Vector3 turn)
    {
        Vector3 to;
        
        to = Quaternion.Euler(turn) * from;
        
        
        return to;
    }
    public static float Distance(Vector3 vec1,Vector3 vec2)
    {
        return Vector2.Distance(new Vector2(vec1.x, vec1.z), new Vector2(vec2.x, vec2.z));
    }
    public static Vector3 Vector3Set(Vector3 vec, string xyz,float value)
    {
        if (xyz == "x")
        {
            vec.Set(value, vec.y, vec.z);
        }
        if (xyz == "y")
        {
            vec.Set(vec.x, value, vec.z);
        }
        if (xyz == "z")
        {
            vec.Set(vec.x, vec.y, value);
        }
        return vec;
    }
}
